<script type="text/javascript" src="/js/our_js/time_table.js"></script>

<!-- Main content wrapper -->
    <div class="wrapper">            
		<table width=70% style="margin-right:auto; margin-left:auto; margin-top:20px;">
                    <tbody>
                        <tr>
			    <td>
                                <div class="formRow" style="padding:0;">
                                    <label>Starting date:</label>
                                    <div class="formRight" style="float:none; margin-right:0; padding-top:5px; margin-left: 80px; width: 180px;">
                                        <input type="text" class="datepicker" id="first_graph"/>
                                    </div>
                                </div>
		            </td>
                            <td>
			        <div class="formRow" style="padding:0;">
                                    <label>End date:</label>
                                    <div class="formRight" style="float:none; margin-right:0; padding-top:5px; margin-left: 60px; width: 180px;">
                                        <input type="text" class="datepicker" id="second_graph"/>
                                    </div>
                                </div>
			    </td>
		            <td>
			        <input type="submit" class="button greenB" style="margin: 5px;" id="submit" value="Построить график" onclick="getTimeTableData();"/>
		            </td>
                        </tr>
                    </tbody>
		</table>            			        
		<div class="widget chartWrapper">
            <div class="title"><img src="/images/icons/dark/graph.png" alt="" class="titleIcon" /><h6>Lines chart</h6></div>
            <div class="body"><div class="chart"></div></div>
        </div>
				<a href="#" title="" class="button basic" style="margin: 5px;"><span>сохранить график в файл</span></a>
		<a href="#" title="" class="button basic" style="margin: 5px;"><span>распечатать</span></a>
		<a href="#" title="" class="button basic" style="margin: 5px;"><span>скачать отчет </span></a>
		
			<div class="line" style="margin-top:20px;"></div>
		
					<table style="margin-right:auto; margin-left:auto;">
					<tbody>
					<tr>
				<td>
					<div class="formRow" style="padding:0;">
                    <label>Starting date:</label>
                    <div class="formRight" style="float:none; margin-right:0; padding-top:5px; margin-left: 80px; width: 180px;">
                        <input type="text" class="datepicker" id="start" />
                    </div>
                </div>
				</td>
				
				<td>
				<div class="formRow" style="padding:0;">
                    <label>End date:</label>
                    <div class="formRight" style="float:none; margin-right:0; padding-top:5px; margin-left: 60px; width: 180px;">
                        <input type="text" class="datepicker" id="end" />
                    </div>
                </div>
				</td>
				<td style="text-align:left;">
				<div class="formRow" style="margin-right:auto; margin-left:auto; width:200px;">
                        <div class="formRight" style="margin-right:0; width:200px;">
                            <select id="sel" name="select2" >
                                <option value="opt1">по времени</option>
                                <option value="opt2">по сайтам</option>
                            </select>           
                        </div>
						<div class="clear"></div>						
                    </div>
					</td>
				<td>
				<input type="button" class="button greenB" style="margin: 5px;" id="time_button" value="Построить таблицу" onclick="getTimeTableDate();" />
				</td>
					</tr>
					</tbody>
					</table>                        
	
            <script type="text/javascript">
                $(document).ready(function(){
                    var site = 'opt2';
                    var time = 'opt1';
                    if($('#sel').val() == time) {
                        $('#site').hide();
                        $('#time').show()
                    }
                    $('#sel').change(function(){
                    if($('#sel').val() == time) {
                        $('#site').hide();
                        $('#time').show()
                    }
                    if ($('#sel').val() == site){
                        $('#time').hide();
                        $('#site').show();
                    }
                    });
                });
            </script>
            <div class="widget" id="time">
            <div class="title"><img src="/images/icons/dark/full2.png" alt="" class="titleIcon" /><h6>если по времени</h6></div>
            <table cellpadding="0" cellspacing="0" border="0" class="display dTable">
            <thead>
            <tr>
            <th>Дата</th>
            <th>Доход</th>
            <th>Доход за баннеры</th>
            <th>Доход за контекстную рекламу</th>
			<th>Доход за рекламу в соц. сетях</th>
            <th>Доход за рекламу в микроблогах</th>
            </tr>
            </thead>
            <tbody id="tbody1">
                
            <?php foreach ($this->statistic as $val) { ?>
                <tr class="gradeA">
                <td><?php echo date('d-M-Y', strtotime($val['date'])); ?></td>
                <td>
                    <?php 
                    if ($val['all_profit'] === null) {
                        echo 0;
                    } else {
                        echo $val['all_profit'].'$'; 
                    }    
                    ?>
                </td>
                <td>
                    <?php 
                    if ($val['banner_profit'] === null) {
                        echo 0;
                    } else {
                        echo $val['banner_profit'].'$'; 
                    }    
                    ?>
                </td>
                <td>
                    <?php 
                    if ($val['context_profit'] === null) {
                        echo 0;
                    } else {
                        echo $val['context_profit'].'$'; 
                    }    
                    ?>
                </td>
                <td>
                    <?php 
                    if ($val['social_profit'] === null) {
                        echo 0;
                    } else {
                        echo $val['social_profit'].'$'; 
                    }    
                    ?>
                </td>
                <td>
                    <?php 
                    if ($val['blog_profit'] === null) {
                        echo 0;
                    } else {
                        echo $val['blog_profit'].'$'; 
                    }    
                    ?>
                </td>
                </tr>
            <?php } ?>
            </tbody>
            
            </table>  
        </div>
		<div class="widget" id="site">
            <div class="title"><img src="/images/icons/dark/full2.png" alt="" class="titleIcon" /><h6>если по сайтам</h6></div>
            <table cellpadding="0" cellspacing="0" border="0" class="display dTable">
            <thead>
            <tr>
            <th>Сайт</th>
			<th>Тематика</th>
			<th>Количество рекламных мест</th>
            <th>Дохода всего</th>
            <th>Доход за баннеры</th>
            <th>Доход за контекстную рекламу</th>
			<th>Отчет</th>
            </tr>
            </thead>
            <tbody>
                
                <?php 
                    foreach ($this->site as $arr){
                        echo '<tr class="gradeA">';
                        echo '<td>'.$arr['url'].'</td>';
                        echo '<td>'.$arr['name'].'</td>';
                        echo '<td>'.$arr['sum'].'</td>';
                        echo '<td>'.$arr['totalSiteGain'].'$</td>';
			echo '<td>'.$arr['totalGainBanner'].'$</td>';
			echo '<td>'.$arr['totalGainContext'].'$</td>';
			echo '<td><a href="#" title="">скачать</a></td>';
            echo '</tr>';
                    }
                
                ?>
   
            </tbody>
            </table>  
        </div>
		
		</div>
